﻿Imports System.Windows.Forms
Imports System.Drawing

Public Class frmCalendar

    Public strData As String
    Public Enum TipoApertura
        SOTTO
        SOPRA
        CENTRO
    End Enum
    Public ModalitaApertura As TipoApertura = TipoApertura.SOTTO

    Private Sub frmCalendario_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        calendario.BackColor = System.Drawing.SystemColors.Info
        calendario.ForeColor = Drawing.Color.Black
        calendario.TitleBackColor = System.Drawing.Color.Purple
        calendario.TitleForeColor = System.Drawing.Color.Yellow

        calendario.FirstDayOfWeek = System.Windows.Forms.Day.Monday
        calendario.ScrollChange = 1
    End Sub

#Region "Eventi form"

    Private Sub frmCalendario_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        Select Case ModalitaApertura
            Case TipoApertura.SOTTO
                Me.Top = Control.MousePosition.Y - 165 + Me.Height
                Me.Left = Control.MousePosition.X
            Case TipoApertura.SOPRA
                Me.Top = Control.MousePosition.Y - 165
                Me.Left = Control.MousePosition.X
            Case TipoApertura.CENTRO
                Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2
                Me.Top = (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2
        End Select


        Me.BringToFront()
    End Sub

    Private Sub me_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Escape Then
            strData = ""
            Me.DialogResult = DialogResult.Cancel
        ElseIf e.KeyCode = Keys.Return Then
            Me.DialogResult = DialogResult.OK
        End If
    End Sub

#End Region

#Region "Selezione Data"

    Private Sub calendario_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles calendario.DateSelected
        strData = e.Start.Date.ToShortDateString
    End Sub

    Private Sub calendario_OnDoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles calendario.OnDoubleClick
        Dim oPoint As Point = Me.PointToClient(Control.MousePosition)
        If oPoint.Y > 50 And oPoint.Y < 140 Then
            Me.DialogResult = DialogResult.OK
        End If
    End Sub

#End Region

End Class